package com.ekgc.addressbook.base.exception;

import com.ekgc.addressbook.base.pojo.vo.ResponseVO;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MultipartException;

/**
 * <b>基础功能 -- 全局异常处理类</b>
 *
 * @author FanSheng
 * @version 1.0
 */
@RestControllerAdvice
public class GlobeExceptionHandler {

	@ExceptionHandler(MultipartException.class)
	public ResponseVO<?> handleMultipartException(MultipartException e) {
		// 不要直接返回e，而是返回自定义错误信息
		return ResponseVO.fail("文件上传失败: " + e.getMessage());
	}

	/**
	 * <b>处理所有控制层抛出的异常</b>
	 * @param e
	 * @return
	 */
	@ExceptionHandler(Exception.class)
	public ResponseVO handlerException(Exception e) {
		return ResponseVO.createExceptionResponseVO(e);
	}
}
